﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Paintball.Libaries
{
    public static class TileHelper
    {
        public static Texture2D Tile(Texture2D texture, int width, int height)
        {
            RenderTarget2D renderer = new RenderTarget2D(ObjectHolder.Game.GraphicsDevice,
                width * texture.Width, height * texture.Height, 
                false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.DiscardContents);

            int textureWidth = texture.Width;
            int textureHeight = texture.Height;

            using (SpriteBatch b = new SpriteBatch(ObjectHolder.Game.GraphicsDevice))
            {
                ObjectHolder.Game.GraphicsDevice.SetRenderTarget(renderer);
                ObjectHolder.Game.GraphicsDevice.Clear(Color.Transparent);
                b.Begin();
                for (int y = 0; y < height; y++)
                    for (int x = 0; x < width; x++)
                        b.Draw(texture, new Rectangle(x * textureWidth, y * textureHeight, textureWidth, textureHeight), Color.White);

                b.End();
                ObjectHolder.Game.GraphicsDevice.SetRenderTarget(null);
            }

            return renderer;
        }
    }
}
